﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>工厂常用术语维护</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
</head>
<body>
    <div style="float: left; width: 100%; margin-left: 10px;">
        <div class="panelSection">
            <div class="easyui-panel " title="角色选择" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="float: left">
                    <select id="selQRole" class="easyui-combobox" data-options="editable:false,panelHeight:'200'"
                        style="width: 150px; height: 20px">
                    </select>
                </div>
                <div style="clear: both;">
                </div>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="常用术语" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="width: 100%; height: 250px" id="commonTerm">
                </div>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="术语维护" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div style="width: 100%;">
                    <div style="float: left">
                        <div class="divLabel" style="margin-bottom: 5px">
                            角色：</div>
                        <select id="selMRole" class="easyui-combobox" data-options="editable:false,panelHeight:'200'"
                            style="width: 150px; height: 20px">
                        </select>
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            常用术语：</div>
                        <input id="txtCommonTerm" class="easyui-textbox" type="text" style="width: 200px;
                            height: 22px" />
                    </div>
                    <div style="float: left; margin-top: 15px; margin-left: 10px">
                        <a id="btnTermAdd" class="easyui-linkbutton" style="width: 100px;">添加</a> <a id="btnTermDele"
                            class="easyui-linkbutton" style="width: 100px; margin-left: 10px;">删除</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="statusMessage" style="font-size: 14px; height: 40px; margin-top: 10px">
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    var page = {
        url: getRootPath() + "/Ashx/YePianContainer/YPContainerStepAttributeHandler.ashx", //后台处理逻辑url
        init: function () { page.bind(); page.initPageData(); },
        bind: function () {
            //添加常用术语
            $("#btnTermAdd").on("click", function () {
                page.postCommonTerm(false);
            });
            //删除常用术语
            $("#btnTermDele").on("click", function () {
                page.postCommonTerm(true);
            });
        },
        //初始化页面数据
        initPageData: function () {
            page.post(page.url, { action: "GetUserRoleList" }, true, function (res) {
                if (res.Result && res.DBTable.length > 0) {
                    //绑定工序备注常用语角色下拉列表
                    $("#selQRole").combobox({ //查询下拉
                        valueField: 'ROLEID',
                        textField: 'ROLENAME',
                        panelHeight: 200,
                        data: res.DBTable, //下拉数据
                        value: res.DBTable[0].ROLEID,
                        onSelect: function (record) {
                            page.bindCommonTerm(record.ROLENAME);
                        }
                    });
                    $("#selMRole").combobox({ //维护下拉
                        valueField: 'ROLEID',
                        textField: 'ROLENAME',
                        panelHeight: 200,
                        data: res.DBTable //下拉数据
                    });
                }
            });
        },
        //绑定标签列表(通过角色名)
        bindCommonTerm: function (roleName) {
            clearMessage();
            $('#txtCommonTerm').textbox('setText', "");
            $("#selMRole").combobox("setValue", "");
            var postForm = { action: "GetCommonTerm", roleName: roleName };
            page.post(page.url, postForm, true, function (result) {
                if (result.Result) {
                    var data = result.DBTable;
                    var htmls = "";
                    for (var i = 0; i < data.length; i++) {
                        htmls += "<a class='easyui-linkbutton' data-fid='" + data[i].FACTORYCOMMONTERMID + "' style='border-color: blue;color:blue; margin:5px;'>" + data[i].TERMVALUE + "</a>"
                    }
                    $("#commonTerm").html(htmls);
                    $.parser.parse("#commonTerm"); //局部刷新样式
                    $("#commonTerm").find(".easyui-linkbutton").each(function () {
                        $(this).on("click", function () {
                            var color = $(this).css("border-color");
                            var text = $(this).text();
                            if (color === "blue") {
                                $(this).css("border-color", "red");
                                $(this).css("color", "red");
                            } else {
                                $(this).css("border-color", "blue");
                                $(this).css("color", "blue");
                            }
                        });
                    })
                }
            });
        },
        //保存常用术语（是否删除）
        postCommonTerm: function (isDele) {
            var postFormData = {
                action: "SaveCommonTerm",
                roleName: "",
                termValue: "",
                factorycommontermId: "",
                isDelete: isDele
            };
            $('#btnTermAdd').linkbutton('disable'); //禁用按钮
            $('#btnTermDele').linkbutton('disable'); //禁用按钮
            if (isDele) {
                $("#commonTerm").find(".easyui-linkbutton").each(function () {
                    var color = $(this).css("border-color");
                    var text = $(this).attr("");
                    if (color === "red") {
                        var fid = $(this).attr("data-fid");
                        postFormData.factorycommontermId += "'" + fid + "',";
                    }
                });
                if (isNullOrWhiteSpaceStr(postFormData.factorycommontermId)) {
                    displayMessage2("请选择术语", false, ["btnTermAdd", "btnTermDele"]);
                    return false;
                }
            } else {
                postFormData.roleName = $('#selMRole').combobox('getText');
                if (isNullOrWhiteSpaceStr(postFormData.roleName)) {
                    displayMessage2("请选择角色", false, ["btnTermAdd", "btnTermDele"]);
                    return false;
                }
                postFormData.termValue = $('#txtCommonTerm').textbox('getText');
                if (isNullOrWhiteSpaceStr(postFormData.termValue)) {
                    displayMessage2("请填写术语", false, ["btnTermAdd", "btnTermDele"]);
                    return false;
                }
            }
            page.post(page.url, postFormData, true, function (result) {
                if (result.Result) {
                    page.bindCommonTerm($('#selQRole').combobox('getText'));
                }
                displayMessage2(result.Message, result.Result, ["btnTermAdd", "btnTermDele"]);
            });
        },
        //post数据（路径，参数，是否异步，成功返回方法）
        post: function (url, param, async, callback) {
            $.ajax({
                type: "Post",
                url: url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    $("body").find(".easyui-linkbutton").each(function () {
                        $(this).linkbutton('enable');
                    });
                }
            });
        }
    };
    page.init();
</script>
